import os
import Reloading

def Warehouse (save, player_warehouse_list: list, player_warehouse_list_name: list, warehouse_level: int, money: int, acc_num):
    list_amount = 0
    for i in player_warehouse_list:
        list_amount += i[1]
    os.system ('cls')
    while (True):
        try :
            print ("\033[39;33m|---------------------------------------")
            print (f"\033[39;33m|\033[39;36m当前仓库有\033[39;32m{len (player_warehouse_list_name)}\033[39;36m种货物")
            print (f"\033[39;33m|\033[39;36m当前仓库有\033[39;32m{list_amount}\033[39;36m单位货物")
            print ("\033[39;33m|---------------------------------------")
            print ("\033[39;33m|\033[39;35m1. 查看仓库详情")
            print ("\033[39;33m|\033[39;32m2. 升级仓库")
            print ("\033[39;33m|\033[39;31m0. 返回")
            print ("\033[39;33m|---------------------------------------\033[0m")
            chos = int (input ("输入需要的功能："))
            if (chos == 1):
                os.system ('cls')
                WarehouseAllGoods (player_warehouse_list, list_amount, warehouse_level)
            elif (chos == 2):
                save, warehouse_level, money, acc_num = WarehouseLevelUp (warehouse_level, money, acc_num)
            elif (chos == 0):
                os.system ('cls')
                return save, warehouse_level, money, acc_num
            else :
                raise ValueError
        except ValueError:
            os.system ('cls')
            print ("\033[1;31m无效选项！\033[0m\n")
# ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————         
def WarehouseAllGoods (player_warehouse_list, list_amount, warehouse_level):
    print ("\033[39;33m|---------------------------------------")
    print (f"\033[39;33m|\033[39;36m仓库\033[39;32m{warehouse_level}\033[39;36m级")
    print (f"\033[39;33m|\033[39;36m仓库可存放\033[39;32m{warehouse_level * 5}\033[39;36m种货物")
    print (f"\033[39;33m|\033[39;36m仓库可存放\033[39;32m{warehouse_level * 30}\033[39;36m单位货物")
    print ("\033[39;33m|---------------------------------------")
    print (f"\033[39;33m|\033[39;36m当前仓库共计有\033[39;32m{len (player_warehouse_list)}\033[39;36m种货物")
    print (f"\033[39;33m|\033[39;36m当前仓库共计有\033[39;32m{list_amount}\033[39;36m单位货物")
    print ("\033[39;33m|---------------------------------------")
    print (f"\033[39;33m|\033[39;36m还可以添加\033[39;32m{(warehouse_level * 5) - len (player_warehouse_list)}\033[39;36m种货物")
    print (f"\033[39;33m|\033[39;36m还可以添加\033[39;32m{(warehouse_level * 30) - list_amount}\033[39;36m单位货物")
    print ("\033[39;33m|---------------------------------------")
    print ("\033[39;33m|货物列表：")
    num = 1
    for i in player_warehouse_list:
        print (f"\033[39;33m|\033[0m{num}. {i[0]} {i[1]}{i[2]}")
        num += 1
    print ("\033[39;33m|---------------------------------------\033[0m")
    input ("按Enter键继续...")
    os.system ('cls')
    return None
# ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
def WarehouseLevelUp (warehouse_level, money, acc_num):
    os.system ('cls')
    need_money = [300, 400, 500, 600, 
                  800, 1000, 1200, 1400, 1500,
                  1800, 2100, 2400, 2700, 3000,
                  3400, 3800, 4200, 4600, 5000]
    while (True):
        try :
            print ("\033[39;33m|---------------------------------------")
            print (f"\033[39;33m|\033[39;36m仓库\033[39;32m{warehouse_level}\033[39;36m级")
            print (f"\033[39;33m|\033[39;36m仓库可存放\033[39;32m{warehouse_level * 5}\033[39;36m种货物")
            print (f"\033[39;33m|\033[39;36m仓库可存放\033[39;32m{warehouse_level * 30}\033[39;36m单位货物")
            print (f"\033[39;33m|\033[39;36m营业可上架\033[39;32m{warehouse_level * 2}\033[39;36m种货物")
            print (f"\033[39;33m|\033[39;36m营业可上架\033[39;32m{warehouse_level * 20}\033[39;36m单位货物")
            print ("\033[39;33m|---------------------------------------")
            if (warehouse_level != 20):
                print (f"\033[39;33m|\033[39;36m升至\033[39;32m{warehouse_level + 1}\033[39;36m级需要\033[39;33m{need_money[warehouse_level - 1]}\033[39;36m₿")
                print (f"\033[39;33m|\033[39;36m持有\033[39;33m{money}\033[39;36m₿")
            elif (warehouse_level == 20):
                print (f"\033[39;33m|\033[39;36m仓库已经满级了！")
            print ("\033[39;33m|---------------------------------------")
            print ("\033[39;33m|\033[39;32m1. 升级仓库")
            print ("\033[39;33m|\033[39;31m0. 返回")
            print ("\033[39;33m|---------------------------------------\033[0m")
            chos = int (input ("输入需要的功能："))
            if (chos == 1):
                if (money >= need_money[warehouse_level - 1]):
                    os.system ('cls')
                    print (f"\033[1;31m你确定要花费\033[1;33m{need_money[warehouse_level - 1]}\033[1;31m₿升级仓库至\033[1;32m{warehouse_level + 1}\033[1;31m级吗？")
                    print (f"\033[1;31m升级后剩余\033[1;33m{money - need_money[warehouse_level - 1]}\033[1;31m₿")
                    print ("\033[1;31m输入其他内容取消升级")
                    print ("\033[1;31m输入Yes以确认升级(区分大小写)")
                    chos = input ("\033[39;34m是否确认升级？：\033[0m")
                    if (chos == 'Yes'):
                        os.system ('cls')
                        money -= need_money[warehouse_level - 1]
                        warehouse_level += 1
                        Reloading.WaerehouseLevelUpLoading ()
                        print (f"\033[38;5;212m仓库已升级至\033[39;32m{warehouse_level}\033[38;5;212m级！")
                        print (f"\033[38;5;212m仓库可存放种类货物增加\033[39;32m5\033[38;5;212m种！")
                        print (f"\033[38;5;212m仓库可存放单位货物增加\033[39;32m30\033[38;5;212m单位！")
                        print (f"\033[38;5;141m营业可上架种类货物增加\033[39;32m2\033[38;5;141m种！")
                        print (f"\033[38;5;141m营业可上架单位货物增加\033[39;32m20\033[38;5;141m单位！\n")
                        save = 0
                        if ((4 not in acc_num) and (warehouse_level >= 20)):
                            acc_num.append (4)
                            print ("\n\033[33m达成成就《\033[38;5;219m仓廪无忧\033[33m》！\033[0m")
                        return save, warehouse_level, money, acc_num
                    else :
                        os.system ('cls')
                        print ("\n\033[1;31m取消升级！\033[0m\n")
                else :
                    os.system ('cls')
                    print ("\n\033[1;31m你的钱不够！\033[0m\n")
            elif (chos == 0):
                os.system ('cls')
                return warehouse_level, money, acc_num
            else :
                raise ValueError
        except ValueError:
            os.system ('cls')
            print ("\033[1;31m无效选项！\033[0m\n")